#ifndef _IO_H_
#define _IO_H_

#include "stm32l1xx.h"

struct io
{
    GPIO_TypeDef        *gpio;
    uint16_t            pin;
};

#define USART_PRINT_NUM                                                         1
#define USART_PRINT_DEFAULT_BAODRATE                                            115200
#if( USART_PRINT_NUM == 1 )
    #define USART_PRINT 							USART1
    #define USART_PRINT_IRQ							USART1_IRQn
    #define USART_PRINT_CLK							RCC_APB2Periph_USART1

    #define USART_PRINT_TX_CLK							RCC_AHBPeriph_GPIOA
    #define USART_PRINT_TX_PORT							GPIOA
    #define USART_PRINT_TX_PIN							GPIO_Pin_9
    #define USART_PRINT_TX_PIN_SOURCE                                           GPIO_PinSource9
    #define USART_PRINT_TX_PIN_AF                                               GPIO_AF_USART1    

    #define USART_PRINT_RX_CLK 							RCC_AHBPeriph_GPIOA
    #define USART_PRINT_RX_PORT							GPIOA
    #define USART_PRINT_RX_PIN							GPIO_Pin_10
    #define USART_PRINT_RX_PIN_SOURCE                                           GPIO_PinSource10
    #define USART_PRINT_RX_PIN_AF                                               GPIO_AF_USART1
#elif( USART_PRINT_NUM == 5 )
    #define USART_PRINT 							UART5
    #define USART_PRINT_IRQ							UART5_IRQn
    #define USART_PRINT_CLK							RCC_APB1Periph_UART5

    #define USART_PRINT_TX_CLK							RCC_APB2Periph_GPIOC
    #define USART_PRINT_TX_PORT							GPIOC
    #define USART_PRINT_TX_PIN							GPIO_Pin_12

    #define USART_PRINT_RX_CLK 							RCC_APB2Periph_GPIOD
    #define USART_PRINT_RX_PORT							GPIOD
    #define USART_PRINT_RX_PIN							GPIO_Pin_2
#endif

#define SPI_NUM 1

#define SPI 			            SPI1
#define SPI_CLK 			        RCC_APB2Periph_SPI1

#define SPI_SCK_PIN 		        GPIO_Pin_5
#define SPI_SCK_GPIO_PORT 		    GPIOA
#define SPI_SCK_GPIO_CLK 		    RCC_AHBPeriph_GPIOA

#define SPI_MISO_PIN 		        GPIO_Pin_6
#define SPI_MISO_GPIO_PORT 		    GPIOA
#define SPI_MISO_GPIO_CLK 		    RCC_AHBPeriph_GPIOA

#define SPI_MOSI_PIN 		        GPIO_Pin_7
#define SPI_MOSI_GPIO_PORT 		    GPIOA
#define SPI_MOSI_GPIO_CLK 		    RCC_AHBPeriph_GPIOA

#define SPI_CS_PIN 			        GPIO_Pin_4
#define SPI_CS_GPIO_PORT 		    GPIOA
#define SPI_CS_GPIO_CLK 		    RCC_AHBPeriph_GPIOA

#define LORA_INT1_PIN			    GPIO_Pin_2
#define LORA_INT1_GPIO_PORT 		GPIOC
#define LORA_INT1_GPIO_CLK 		    RCC_AHBPeriph_GPIOC

#define LORA_INT2_PIN			    GPIO_Pin_3
#define LORA_INT2_GPIO_PORT 		GPIOC
#define LORA_INT2_GPIO_CLK 		    RCC_AHBPeriph_GPIOC

#define LORA_INT3_PIN			    GPIO_Pin_4
#define LORA_INT3_GPIO_PORT 		GPIOC
#define LORA_INT3_GPIO_CLK 		    RCC_AHBPeriph_GPIOC

#define LORA_INT4_PIN			    GPIO_Pin_5
#define LORA_INT4_GPIO_PORT 		GPIOC
#define LORA_INT4_GPIO_CLK 		    RCC_AHBPeriph_GPIOC

#define LORA_INT5_PIN			    GPIO_Pin_6
#define LORA_INT5_GPIO_PORT 		GPIOC
#define LORA_INT5_GPIO_CLK 		    RCC_AHBPeriph_GPIOC

#define LORA_RST_PIN			    GPIO_Pin_7
#define LORA_RST_GPIO_PORT 		    GPIOC
#define LORA_RST_GPIO_CLK 		    RCC_AHBPeriph_GPIOC

#define LORA_RXMODE_PIN			    GPIO_Pin_8
#define LORA_RXMODE_GPIO_PORT 		GPIOC
#define LORA_RXMODE_GPIO_CLK 		RCC_AHBPeriph_GPIOC

#define LORA_TXMODE_PIN			    GPIO_Pin_9
#define LORA_TXMODE_GPIO_PORT 		GPIOC
#define LORA_TXMODE_GPIO_CLK 		RCC_AHBPeriph_GPIOC

#define LORA_IRQ1_HANDLE            EXTI2_IRQHandler
#define LORA_IRQ2_HANDLE            EXTI3_IRQHandler
#define LORA_IRQ3_HANDLE            EXTI4_IRQHandler
#define LORA_IRQ4_HANDLE            EXTI9_5_IRQHandler

#endif
